DIM

Syntax: DIM array (index1 {index} ) {,array (index {index} ) }
Location: QL ROM

The command DIM allows you to set up one or more SuperBASIC arrays which may be of string, integer or floating point type. Each index must be an integer in the range 0...32767.

Numeric Arrays
Each index defines the maximum number of elements (less one) in any one direction.

DIM a(10)  sets up a floating-point array a containing 11 elements, a(0) to a(10);

String Arrays
String arrays are peculiar and have various differences to both un-dimensioned strings and number arrays. In a string array, the final index contains the maximulements will result in a truncated string). For example:

DIM a$(10)
sets up a one-dimensional string array a$ with a maximum of 10 characters. This is similar to a$=FILL$(" ",10), except that a$ now has a maximum length;

DIM z$(10,9)
sets up a two-dimensional string array, which can hold 11 strings (z$(0) to z$(10)), each up to 9 characters long.

When a string array is set up with DIM each entry is set to a nul string (""). The zero'th element of each string array contains the actual length of that string, for example:

DIM a$(10,10): a$(1)='Hello': PRINT a$(1,0)

will return the value 5, as will PRINT LEN(a$(1)).

NOTE:
The Turbo compiler alters DIM in compiled programs to enable you to re-dimension arrays without losing their original contents. You may therefore need to physically set the contents of arrays to zero (or nul strings) to ensure that a program works properly when compiled.

The Turbo and Supercharge compilers insist that strings are all dimensioned as string arrays. They do however also alter the way in which string arrays work sothat they operate more like un-dimensioned strings. Un-dimensioned strings may also upset Qliberated tasks!

WARNING:
DIM and dimensioned variables can crash the system in certain instances.

CROSS-REFERENCE:
DIMN allows you to find out the maximum sizes of an array.
LEN allows you to find the length of a string.
